package bx.com.smartcashier.application;

import android.app.Activity;
import android.app.Application;

import java.util.ArrayList;
import java.util.List;

public class BxApplication extends Application {

    private static List<Activity> activityList;
    @Override
    public void onCreate() {
        super.onCreate();
        activityList=new ArrayList<>();
    }

    /**
     * 保存Activity到现有列表中
     *
     * @param activity
     */
    public static void addActivity(Activity activity) {
        if (!activityList.contains(activity))
            activityList.add(activity);//把当前Activity添加到集合中
    }

    /**
     * 销毁单个activity
     */
    public static void removeActivity(Activity activity) {
        if (activityList.contains(activity)) {
            activityList.remove(activity);
            activity.finish();
        }
    }


    /**
     *     销毁所有的activity
     */
    public static void removeALLActivity() {
        for (Activity activity : activityList) {
            activity.finish();
        }
    }
}
